home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoConvertToSmall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.5 KB  |  273 lines

  1. /*
  2.  *   $RCSfile: undoConvertToSmall.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "openlog.h"
  61. #include "logrecs.h"
  62. #include "logaction.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "sm_extfuncs.h"
  67. #include "log_extfuncs.h"
  68. #include "util_funcs.h"
  69. #include "log_intfuncs.h"
  70. #include "thread_globals.h"
  71. #include "bf_globals.h"
  72. #include "trans_globals.h"
  73. #include "sm_macro.h"
  74. #ifdef INIT_LRC_IS_LSN
  75. #   include "log_globals.h"
  76. #endif
  77.  
  78.  
  79.  void
  80. undoConvertToSmall (
  81.  
  82.     LOGRECORDHDR        *recordHeader 
  83. )
  84. {
  85.  
  86.     GROUPLINK            *groupLink;
  87.     SLOTTEDPAGE            *slottedPage;
  88.     PID                    *pid;
  89.     SMALLOBJ            *logObj;
  90.     int                    oldDataSize;
  91.     SMALLOBJ            *origObj;
  92.     PAGESLOT            *slotPtr;
  93.     OID                    *oid;
  94.     LOGRECORDINFO       recordInfo;
  95. #ifdef INIT_LRC_IS_LSN
  96.     LRC                 tempLRC;
  97.     LRC                 *lrc = &tempLRC;
  98. #else
  99.     LRC                 *lrc;
  100. #endif /* INIT_LRC_IS_LSN; */
  101.     LSN                 lsn;
  102.     FORCEMARK           forceMark;
  103.     BOOL                actionDone; /* Indicates whether the action
  104.                                        was ever performed on the page */
  105.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  106.  
  107.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  108.  
  109.     /*
  110.      *    get a pointer to the page for the record
  111.      */
  112.     pid = &(recordHeader->actionPid);
  113.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  114.  
  115.     /*
  116.      *    get pointer to oid, and the old object data
  117.      */
  118.     oid = (OID*) GET_LOG_IMAGE(recordHeader, 0);
  119.     logObj = (SMALLOBJ*) GET_LOG_IMAGE(recordHeader, 2);
  120.     oldDataSize = GET_LOG_IMAGE_SIZE(recordHeader, 2);
  121.  
  122.     /*
  123.      *    read in the page
  124.      */
  125.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
  126.  
  127.         SM_ERROR(TYPE_FATAL, Active->errno);
  128.     }
  129.     groupLink->pageHash->pageType = PAGE_SLOTTED;
  130.  
  131.     /*
  132.      *    get a pointer to the slotted page
  133.      */
  134.     slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  135.     if (CHECK_SLOTTED_MAGIC(slottedPage)) {
  136.         SM_ERROR(TYPE_FATAL, Active->errno);
  137.     }
  138.  
  139.     /*
  140.      *  See if the action was actually done
  141.      */
  142.      actionDone = compareLRC(&(recordHeader->actionLRC), &(slottedPage->header.lrc) ) <= 0;
  143.  
  144.     /*
  145.      *  it is possible that the action
  146.      *  never made it to the page on the server, so missing update
  147.      *  information may need to be recordedjj
  148.      *
  149.      *  Process any missing updates, and return a pointer to
  150.      *  the lrc to increment.  This will either be the lrc on the
  151.      *  slotted page, or the lrc in the missingUpdatePageTable
  152.      */
  153.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  154.                          &(slottedPage->header.lrc),
  155.                          groupLink->pageHash, recordHeader, PAGE_SLOTTED);
  156.  
  157.     /*
  158.      *    increment the lrc on the page
  159.      */
  160.     GENERATE_LRC(lrc);
  161.  
  162.     SM_ASSERT(LEVEL_3, logObj->objectHdr.properties & P_LARGEOBJ);
  163.  
  164.     if (logObj->objectHdr.properties & P_HEADERONPAGE) { 
  165.  
  166.         /*
  167.          *    Log the undo of the conversion
  168.          */
  169.         recordInfo.action       = LOG_ACTION_CONVERT_TO_LARGEROOT;
  170.         recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  171.         recordInfo.imageCount   = 2;
  172.         recordInfo.actionPid    = pid;
  173.         recordInfo.actionLRC    = lrc;
  174.         recordInfo.imageSize[0] = sizeof(OID);
  175.         recordInfo.imageData[0] = (VOID *) oid;
  176.         recordInfo.imageSize[1] = oldDataSize;
  177.         recordInfo.imageData[1] = (VOID *) logObj;
  178.         recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  179.         recordInfo.flags        = NOFLAGS;
  180.  
  181.     } else {
  182.  
  183.         /*
  184.          *    Log the undo of the conversion
  185.          */
  186.         recordInfo.action       = LOG_ACTION_CONVERT_TO_LARGEHDR;
  187.         recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  188.         recordInfo.imageCount   = 2;
  189.         recordInfo.actionPid    = pid;
  190.         recordInfo.actionLRC    = lrc;
  191.         recordInfo.imageSize[0] = sizeof(OID);
  192.         recordInfo.imageData[0] = (VOID *) oid;
  193.         recordInfo.imageSize[1] = oldDataSize;
  194.         recordInfo.imageData[1] = (VOID *) logObj;
  195.         recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  196.         recordInfo.flags        = NOFLAGS;
  197.     }
  198.  
  199.     /* write the record to the log */
  200.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec,
  201.                                      &recordInfo, &lsn, NOFLAGS)) < 0) {
  202.         SM_ERROR(TYPE_FATAL, Active->errno);
  203.     }
  204.  
  205.     /* mark the page dependency */
  206. #ifndef INIT_LRC_IS_LSN
  207.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  208. #endif
  209.  
  210.     /*
  211.      *    perform the undo by copying the old data
  212.      *    if action was performed
  213.      */
  214.     if (actionDone) {
  215.  
  216. #ifdef INIT_LRC_IS_LSN
  217.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  218. #endif
  219.  
  220.         /*
  221.          *    Get a pointer to the slot and then the object
  222.          */
  223.         SM_ASSERT(LEVEL_3, oid->diskAddr.slot < slottedPage->header.slotCount);
  224.         slotPtr = GETSLOTPTR(slottedPage, oid->diskAddr.slot);
  225.         SM_ASSERT(LEVEL_3, oid->diskAddr.unique == slotPtr->unique);
  226.         origObj  = GETOBJECTPTR(slottedPage, slotPtr);
  227.  
  228.         /*
  229.           *    Replace the object header and data
  230.          */
  231.         if (logObj->objectHdr.properties & P_HEADERONPAGE) {
  232.  
  233.             /* 
  234.              *  Undo the conversion by inserting the slotted root and
  235.              *  updating the object header.  This will properly handle
  236.              *  the case were the object is moved.
  237.              */
  238.             if (sm_AppendToSmallObj(slottedPage, logObj->data, oid, sizeof(LGSLOTROOT)))
  239.             {
  240.  
  241.                 SM_ERROR(TYPE_FATAL, esmINTERNAL);
  242.             }
  243.  
  244.  
  245.             /* 
  246.              *    restore the pointer to the object, as it may have moved
  247.              */
  248.             slotPtr = GETSLOTPTR(slottedPage, oid->diskAddr.slot);
  249.             SM_ASSERT(LEVEL_3, oid->diskAddr.unique == slotPtr->unique);
  250.             origObj  = GETOBJECTPTR(slottedPage, slotPtr);
  251.  
  252.         } else {
  253.             /* Undo the conversion by replacing the root pid. */
  254.             *((SHORTPID*)origObj->data) = *((SHORTPID*)logObj->data);
  255.  
  256.             /* number of free bytes on the page has not changed */
  257.         }
  258.  
  259.         origObj->objectHdr = logObj->objectHdr;
  260.         slottedPage->header.largeCount++;
  261.     }
  262.  
  263.     /*
  264.      *    signal the semaphore and unfix the page, dirty the page if the
  265.      *    action was done.
  266.      */
  267.     sm_AuditSlotPage(slottedPage);
  268.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  269.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  270.  
  271.     return;
  272. }
  273.